<?php $this->_extends('_layouts/main_layout'); ?>
<?php $this->_block('resource'); ?>
	<script type="text/javascript" src="<?php echo JS_DIR; ?>imgpreview.full.0.22.jquery.js"></script>
<?php $this->_endblock(); ?>
<?php $this->_block('title'); ?>
	Email Offers
<?php $this->_endblock(); ?>

<?php $this->_block('contents'); ?>

<div id="content" class="box">
	<h1>Email Offers</h1>
	<div id="menu" class="box">
		<ul class="box">
			<li><a href="<?php echo url('offermanager/add');?>"><span>Add</span></a></li>
			<li><a href="javascript:void(0);" id="oeswitch"><span><?php echo ($offerEmailSwitch == 'on')? 'Stop' : 'Run' ?></span></a></li>
		</ul>
		<script>
			$('#oeswitch').click(function(){
				$.ajax({
					type: 'POST',
					url: '<?php echo url('offermanager'); ?>',
					success: function(data){
								$('#oeswitch span').html(data);
							 }
				});
			});
			$(function(){
				$('.imgPreview').imgPreview();
			});
		</script>
	</div>
		<?php if (isset($infos)) 
				{
					foreach ($infos as $info)
					{
		?>
				<p class="msg info"><?php echo $info;?></p>
		<?php		}
				}
		?>
	<fieldset>
		<legend>Email Offers</legend>
		<table class="full-size" style="text-align: center;">
			<thead>
				<tr>
					<th style="width:10%">Site</th>
					<th style="width:15%">Name</th>
					<th style="width:15%">Subject</th>
					<th style="width:10%">Partner</th>
					<th style="width:5%">Offer #</th>
					<th style="width:5%">Order</th>
					<th style="width:5%">Picture URL</th>
					<th style="width:3%">Picture Width</th>
					<th style="width:3%">Picture Height</th>
					<th style="width:5%">Link URL</th>
					<th style="width:9%">Tosent Date</th>
					<th style="width:3%">Gender</th>
					<th style="width:10%">Operate</th>
				</tr>
			</thead>
			<tbody>
				<?php 
					if ($emailOffers && count($emailOffers) > 0):
						foreach($emailOffers as $emailOffer): 
				?>
					<tr>
						<td><?php echo $sites[$emailOffer['site_id']]; ?></td>
						<td><?php echo $emailOffer['name']; ?></td>
						<td><?php echo $emailOffer['subject']; ?></td>
						<td><?php echo $emailOffer['offer_name']; ?></td>
						<td><?php echo $emailOffer['offer_id'];?></td>
						<td><?php echo $emailOffer['ord'];?></td>
						<td><a class="imgPreview" href="<?php echo $emailOffer['picture_url']; ?>">Preview</a></td>
						<td><?php echo $emailOffer['picture_width'];?></td>
						<td><?php echo $emailOffer['picture_height'];?></td>
						<td><a href="<?php echo $emailOffer['link_url']; ?>" title="<?php echo $emailOffer['link_url']; ?>" target="_blank">Click</a></td>
						<td><?php echo $emailOffer['tosent_date'];?></td>
						<td>
							<?php 
								switch ($emailOffer['gender']){
									case "":	echo "All";	break;
									case "M":	echo "Male";	break;
									case "F":	echo "Female";	break;
									default:	echo "All";	break;
								}
							?>
						</td>
						<td>
							<a href="<?php echo url('offermanager/update', array('id'=>$emailOffer['id']));?>">Edit</a>
							<a href="<?php echo url('offermanager/delete', array('id'=>$emailOffer['id']));?>">Delete</a>
						</td>
					</tr>
				<?php 
						endforeach; 
					endif;
				?>
			</tbody>
		</table>
	</fieldset>
	<fieldset>
		<legend>Test send</legend>
		<form id="formsend" action="<?php echo url('email/testoffersofweek'); ?>" method="POST">
			<dl>
				<dt style="width:90px; float:left;">Send to:</dt>
				<dd style="float:left; width:870px; margin:0;">
					<input type="text" id="userEmail" name="userEmail"style="width:300px;" />
				</dd>
				
				<dt style="width:90px; float:left;"> </dt>
				<dd style="float:left; width:870px; margin:0;">
					<input type="submit" id="sub" name="sub" value="Send"  />
				</dd>
			</dl>
		</form>
	</fieldset>
</div>
<?php $this->_endblock(); ?>